<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Common {
    /**
     * [getParams description]
     * @param  [type] $params url字符串
     * @return [type]         字符串数组
     */
    public function getParams( $params )
    {
        $result=array();
        $str=explode('&', $params);
        for($i=0;$i<count($str);$i++){
            $temp=explode('=', $str[$i]);
            $result[$temp[0]]=$temp[1];
        }
        return $result;
    }
    /**
     * 获取页数和每页显示总数
     * @param  [type] $str [description]
     * @return [type]      [description]
     */
    public function getPage($str,$split='-',$cut='.html'){
        $str=str_replace($cut, '', $str);
        $arr = array();
        $arr = explode($split, $str);
        return $arr;
    }
    /**
     * 获取分页信息
     * @param  [type] $current_page [description]
     * @param  [type] $each_page    [description]
     * @param  array  $list         [description]
     * @return [type]               [description]
     */
    public function pageInfo($current_page,$each_page,$list=array()){
        //首页
        $first_page=1;
        //总数
        $page_num=count($list);
        //尾页
        $end_page=ceil($page_num/$each_page);
        //前一页
        if($current_page>1){
            $pre_page=$current_page-1;
        }else{
            $pre_page='';
        }
        //后一页
        if($current_page>=$end_page){
            $next_page='';
        }else{
            $next_page=$current_page+1;
        }
        $pageInfo['current_page']=$current_page;
        $pageInfo['each_page']=$each_page;
        $pageInfo['page_num']=$page_num;
        $pageInfo['pre_page']=$pre_page;
        $pageInfo['next_page']=$next_page;
        $pageInfo['first_page']=$first_page;
        $pageInfo['end_page']=$end_page;
        $pageInfo['content']=array_slice($list, ($current_page-1)*$each_page,$each_page);
        return $pageInfo;
    }
    /**
     * 重定向
     * @param  [type] $url [description]
     * @return [type]      [description]
     */
    public function redirect($url) {
        echo "<script language='javascript'>window.location.href='$url'</script>";
    }
    public function getElectiveStudent($str,$split='-'){
        $arr = array();
        $arr = explode($split, $str);
        return $arr;
    }
}

/* End of file Common.php */